#include <QtGui>
#include "test.h"

Test::Test(QWidget *fp_parent, Qt::WFlags f_flags)
: QWidget(fp_parent, f_flags)
{
	resize(QSize(400, 300));

	mp_propertyManager = new QtVariantPropertyManager();

	mp_dataRoot =
		mp_propertyManager->addProperty(QtVariantPropertyManager::groupTypeId(),
		QLatin1String("Group Property"));

	// create some test data...
	QtVariantProperty *item;
	item = mp_propertyManager->addProperty(QVariant::Bool, QLatin1String("Bool Property"));
	item->setValue(true);
	mp_dataRoot->addSubProperty(item);

	mp_insertAfter = item;

	item = mp_propertyManager->addProperty(QtVariantPropertyManager::flagTypeId(),
		QLatin1String("Flag Property"));
	item->setAttribute(QLatin1String("flagNames"), QStringList() <<
		"Flag0"<< "Flag1"<< "Flag2");
	mp_dataRoot->addSubProperty(item);

	QtVariantEditorFactory *variantFactory = new QtVariantEditorFactory();
	mp_propertyBrowser = new QtTreePropertyBrowser(this);
	mp_propertyBrowser->setFactoryForManager(mp_propertyManager, variantFactory);
	mp_propertyBrowser->addProperty(mp_dataRoot);
	mp_propertyBrowser->setContextMenuPolicy(Qt::CustomContextMenu);

	connect(mp_propertyBrowser,
		SIGNAL(customContextMenuRequested(const QPoint &)),
		this, SLOT(contextMenu(const QPoint &)));

}

Test::~Test()
{

}

void Test::contextMenu(const QPoint &f_position)
{
	QtVariantProperty *item;
	item = mp_propertyManager->addProperty(QVariant::String,
		QLatin1String("New Text Property"));

	mp_dataRoot->insertSubProperty(item,mp_insertAfter);
}
